package com.bwhx.eruler.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bwhx.eruler.bean.Feedback;
import com.bwhx.eruler.bean.Notice;
import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.bean.Staff;
import com.bwhx.eruler.service.FeedbackService;

@Controller
public class FeedbackController extends BaseController {
	

	
	@Autowired
	FeedbackService feedbackService;
	@ResponseBody			
	@RequestMapping(value = "/page.feedbackList.ashx")
	 public Map staffList(Integer page,Integer rows,Feedback feedback, @RequestBody String b) {
		 log.info(b);
		//每页的开始记录
        int start = (page-1)*rows;
        Page p = new Page(start,rows,feedback);
		Map<String,Object> map = new HashMap<String,Object>();
		try{
			List<Feedback> list = feedbackService.list(p);
			Integer i  = feedbackService.count(feedback);


			map.put("total",i );//total键 存放总记录数，必须的  A
			map.put("rows",list);//rows键 存放每页记录 list 
			
		}catch(Exception e){
			log.error(getTrace(e));
			map.put("meg", "失败！");
			map.put("status", "0");
		}
		
	    return map;  
	  }
	
	@ResponseBody
	@RequestMapping(value = "/page.updateFeedback.ashx")
	public String saveOrUpdateStaff(Feedback feedback,HttpSession session) {
		
		Staff staff = (Staff)session.getAttribute("staff");
		String name = staff.getsName();
		feedback.setfPStaff(name);
		feedback.setfPDateTime(System.currentTimeMillis()/1000);
		feedback.setfIsProcess(1);

		feedbackService.update(feedback);

		
	    return "success";  
	  }
	
	
	@ResponseBody
	@RequestMapping(value = "/page.everyone.saveFeedback.ashx")
	public String saveStaff(Feedback feedback,HttpSession session) {
		
		Staff staff = (Staff)session.getAttribute("staff");
		String name = staff.getsName();
		feedback.setfStaff(name);
		feedback.setfDateTime(System.currentTimeMillis()/1000);
		feedback.setfIsProcess(0);

		feedbackService.save(feedback);

		
	    return "success";  
	  }
	

}
